using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Audio;

namespace Pavilion
{
    public class Sound
    {
        static private AudioEngine audioEngine;
        static private WaveBank waveBank;
        static private SoundBank soundBank;
        private Cue cue;

        public Sound()
        {
            audioEngine = new AudioEngine(@"Resources\Sound\SoundWave.xgs");
            waveBank = new WaveBank(audioEngine, @"Resources\Sound\Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, @"Resources\Sound\Sound Bank.xsb");
        }

        public void Initialize(string name)
        {
            cue = soundBank.GetCue(name);
        }

        static public void Update()
        {
            audioEngine.Update();
        }

        public void play()
        {
            if (!cue.IsPlaying)
            {
                if (cue.IsPrepared)
                    cue.Play();
                else
                {
                    //prepares the cue to play the music
                    cue = soundBank.GetCue(cue.Name);
                    cue.Play();
                }
            }
        }

        public void stop()
        {
            cue.Stop(AudioStopOptions.Immediate);
        }
    }
}
